“Pointer arithmetic”指在C/C++等语言中对指针进行加减运算(如 p+1、p-2、p2-p1),用于在同一数组/连续内存块中按元素大小移动位置。常见规则是:指针加1会前进一个元素(步长等于所指类型的字节数),而不是前进1个字节。该术语也常引申为“依赖内存布局进行的低层地址计算”。
/ˈpɔɪntər ˌærɪθˈmɛtɪk/
Pointer arithmetic lets you move through an array using a pointer.
指针算术让你可以用指针在数组中逐个移动。
In C, pointer arithmetic is only well-defined within the bounds of the same array, so adding past the end can cause undefined behavior.
在C语言中,指针算术只在同一数组的边界内才有明确含义;加到数组末尾之外可能导致未定义行为。
该短语由 pointer(指针) + arithmetic(算术/算术运算) 组成。Pointer源自“point(指向)”的概念,表示“指向某处地址的引用”;arithmetic来自希腊语传统中对“数字与运算”的称呼。合起来即“对指针进行算术式的加减计算”,强调它不同于普通整数运算:其步长与所指类型大小相关。